@extends("layout.admin")

@section("title")
    岗位管理列表
@endsection

@section("content")
    {{--列表--}}
    <div class="layui-card-body ">
        <script type="text/html" id="toolbar">
            <div class="layui-btn-container">
                @if(_can('admin.post.create'))<a class="layui-btn layui-btn-sm" onclick="admin.openLayerForm('{{route("admin.post.create")}}', '添加岗位分组', 'POST', '500px', '350px')"><i class="layui-icon"></i>添加岗位分组</a>@endif
            </div>
        </script>
        <table lay-filter="table-hide" style="display: none"  lay-data="{height:'full-310', cellMinWidth: 80,toolbar: '#toolbar',defaultToolbar:['filter'],id:'table',limit:{{$data['per_page']}}}">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:80, fixed: 'left', unresize: true, sort: true}">编号</th>
                <th lay-data="{field:'name'}">名称</th>
                <th lay-data="{field:'sort',edit: 'text'}">排序</th>
                <th lay-data="{field:'created_at'}">创建时间</th>
                <th lay-data="{field:'updated_at'}">更新时间</th>
                <th lay-data="{field:'op',fixed: 'right', width:220, align:'center',toolbar: '#buttons'}">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($data['data'] as $vo)
                <tr>
                    <td>{{ $vo['id'] }}</td>
                    <td>{{ $vo['name'] }}</td>
                    <td>{{ $vo['sort'] }}</td>
                    <td>{{ $vo['created_at'] }}</td>
                    <td>{{ $vo['updated_at'] }}</td>
                    <td>
                        <script type="text/html" id="buttons">
                            <a class="layui-btn layui-btn-xs" lay-event="more">更多 <i
                                    class="layui-icon layui-icon-down"></i></a>
                        </script>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        @include("layout.page")
    </div>
@endsection

@section('script')
    <script>
        var idx=-1;
        layui.use(['form', 'table', 'layer','dropdown'], function () {
            var table = layui.table;
            var form = layui.form,dropdown = layui.dropdown;
            table.init("table-hide");
            table.on('edit(table-hide)', function(obj){
                var value = obj.value
                var id = obj.data.id
                $.post("{{route('admin.post.changeSort')}}",{id:id,value:value,_token:'{{ csrf_token() }}'},function(data){
                    if(data <= 0){
                        layer.msg("操作失败",{icon:5})
                    }
                })
            });
            table.on('tool(table-hide)', function (obj) {
                var that = this
                    , res = obj.data;
                //更多下拉菜单
                let buttons = [
                        @if(_can('admin.post.index')){title: '岗位管理', id: 'exam',type:"link",link:"{{ route_uri(session("guard").".post.index.attach")}}",params:{group_id: res.id}},@endif
                        @if(_can('admin.post.update')){title: '编辑分组', id: 'update',type:'openLayerForm',link:"{{ route_uri(session("guard").".post.update")}}",params:{id: res.id},set:{title:"编辑分组",method:"POST",width:"500px",height:"350px",repush:0,dome:"#update"}},@endif
                        @if(_can('admin.post.destroy')){title: '删除分组', id: 'del',type:'tableDataDelete',link:"{{ route_uri(session("guard").".post.destroy") }}",params:{id:res.id},set:{dome:this,title:"是否删除当前分组"}} @endif
                ]
                dropdown.render(tableButtonGroup(that,buttons))
            });
            admin.paginate("{{ $data['total'] }}", "{{ $data['current_page'] }}", "{{ $data['per_page'] }}");
        });
    </script>
    <script src="{{asset('js/layCommon.js')}}"></script>
@endsection

